package jUnit;

public class Subscription {
	private int price; // subscription total price in euro-cent
	private int length; // length of subscription in months

	// constructor with Cent :
	public Subscription(int p, int n) {
		price = p;
		length = n;
	}
	
	// constructor with Euro
	public Subscription(double p, int n) {
		price = (int) (p*100);
		length = n;
	}

	/**
	 * Calculate the monthly subscription price in euro, rounded up to the
	 * nearest cent.
	 * @throws SubscriptionEndException 
	 */
	public double pricePerMonth() throws SubscriptionEndException {
		
		if (length == 0){
			throw new SubscriptionEndException();
		}
		double r = Math.round((double) price / (double) length)/100.0;
		return r;
		
	}

	/**
	 * Call this to cancel/nulify this subscription.
	 */
	public void cancel() {
		length = 0;
	}
}
